<extend name="Base/common"/>
<block name="head_css">
<link href="__PUBLIC__/css/font-awesome.min.css" rel="stylesheet">
<link href="__PUBLIC__/css/bootstrap-switch.css" rel="stylesheet">
<link href="__PUBLIC__/css/awesome-bootstrap-checkbox.css" rel="stylesheet">
</block>
<block name="body">
    <div class="select_ins insurance">
        <div class="width1000">
            <div class="step_info">
                <div class="write_info on">录入保单信息</div>
                <div class="get_price">获取精确报价</div>
                <div class="cash_money">支付保单</div>
                <div style="clear:both"></div>
            </div>
            <div class="ins_tab">
                <a href="javascript:void(0);" class="f_l ins_tab_li">定制我的车险</a>
            </div>
            <form action="__SELF__" method="post" class="form_all" id="forms">
                <div class="ins_car_type select_label">
                    <label for="stype1" class="on">
                        全面 <span id="m_0"></span>
                    </label>
                    <input type="radio" class="hide" id="stype1" name="stype" value="0" />
                    <label for="stype2">
                        经济 <span id="m_1"></span>
                    </label>
                    <input type="radio" class="hide" id="stype2" name="stype" value="1" />
                    <label for="stype3">
                        基本 <span id="m_2"></span>
                    </label>
                    <input type="radio" class="hide" id="stype3" name="stype" value="2" />
                    <label for="stype4" id="custom_label">
                        自定义
                    </label>
                    <input type="radio" class="hide" id="stype4" name="stype" value="3" />
                </div>
                <p class="ins_more_tit">
                    商业保险
                </p>
                <volist name="kindlist" id="kind">
                <div class="clearfix ins_select_list">
                        <input type="hidden" name="kinds[{$kind.C_KIND_CDE}][c_kind_cde]" value="{$kind.C_KIND_CDE}" />
                        <input type="hidden" name="kinds[{$kind.C_KIND_CDE}][n_seat_num]" value="{$kind.N_SEAT_NUM}" />
                    <div class="col-sm-3">
                        <div class="checkbox">
                            <input type="checkbox" class="styled" id="ck_{$kind.N_SEQ_NO}" name="kinds[{$kind.C_KIND_CDE}][flag]" data="{$kind.C_KIND_CDE}" value="1" <neq name="kind['opts'][0]['value']" value="$kind['N_DEFAULT_AMT']">checked="checked"</neq> />
                            <label for="ck_{$kind.N_SEQ_NO}">
                                {$kind.C_KIND_NAME|str_replace="机动车","",###|str_replace="责任保险","责任险",###}
                            </label>
                            <a tabindex="0" role="button" data-toggle="popover" data-trigger="focus" title="{$kind.C_KIND_NAME}" data-content="{$kind.C_DESC}">
                            <span class="ins_help" title="详情"></span></a>
                        </div>
                    </div>
                    <div class="col-sm-7 f_l">
                        <eq name="kind['C_AMT_FLAG']" value="02">
                        <div class="buttonset-rd">
                        <volist name="kind['opts']" id="vo" key="k">
                            <eq name="k" value="1">
                                <input type="hidden" name="kinds[{$kind.C_KIND_CDE}][noflag]" value="{$vo['value']}" />
                            <else />
                            <input type="radio" id="k_{$kind.N_SEQ_NO}_{$k}" name="kinds[{$kind.C_KIND_CDE}][n_amt]" value="{$vo.value}" <eq name="vo['value']" value="$kind['N_DEFAULT_AMT']">checked="checked"</eq> />
                            <label for="k_{$kind.N_SEQ_NO}_{$k}">{$vo.label}</label>
                            </eq>
                        </volist>
                        </div>
                        <else />
                            <input type="hidden" name="kinds[{$kind.C_KIND_CDE}][n_amt]" value="{$kind['N_DEFAULT_AMT']}">
                        </eq>
                    </div>
                    <div class="col-sm-2 f_l">
                        <notempty name="kind['bjmp']">
                        <input type="hidden" name="kinds[{$kind['bjmp']['C_KIND_CDE']}][c_kind_cde]" value="{$kind['bjmp']['C_KIND_CDE']}">
                        <input type="hidden" name="kinds[{$kind['bjmp']['C_KIND_CDE']}][n_seat_num]" value="{$kind['bjmp']['N_SEAT_NUM']}">
                        <input type="hidden" name="kinds[{$kind['bjmp']['C_KIND_CDE']}][noflag]" value="{$kind['bjmp']['opts'][0]['value']}">
                        <input type="hidden" name="kinds[{$kind['bjmp']['C_KIND_CDE']}][n_amt]" value="{$kind['bjmp']['opts'][1]['value']}">
                        <input class="bswitch" type="checkbox" name="kinds[{$kind['bjmp']['C_KIND_CDE']}][flag]" value="1" data-label-text="不计免赔" data-on-text="投保" data-off-text="不投保" checked="checked">
                        </notempty>
                    </div>
                </div>
                </volist>
                <p class="ins_more_tit">
                    交强险
                </p>
                <div class="clearfix ins_select_list">
                    <div class="col-sm-3">
                        <div class="checkbox">
                            <input type="checkbox" class="styled" id="ck_jqx" name="ck_jqx" checked="checked" disabled />
                            <label for="ck_jqx">
                                交强险
                            </label>
                            <a tabindex="0" role="button" data-toggle="popover" data-trigger="focus" title="交强险" data-content="在发生事故时，保险公司会根据条款来赔偿对对方（人或物）造成的损失。">
                            <span class="ins_help" title="详情"></span></a>
                        </div>
                    </div>
                    <div class="col-sm-7 f_l">
                        <p class="form-control-static" id="m_jqx"></p>
                    </div>
                </div>
                <div class="clearfix ins_select_list">
                    <div class="col-sm-3">
                        <div class="checkbox">
                            <input type="checkbox" class="styled" id="ck_ccs" name="ck_ccs" checked="checked" disabled />
                            <label for="ck_ccs">
                                车船使用税
                            </label>
                            <a tabindex="0" role="button" data-toggle="popover" data-trigger="focus" title="车船使用税" data-content="车船使用税是对行驶于公共道路的车辆和航行于国内河流、湖泊或领海口岸的船舶,按照其种类(如机动车辆、非机动车辆、载人汽车、载货汽车等)、吨位和规定的税额计算征收的一种使用行为税。">
                            <span class="ins_help" title="详情"></span></a>
                        </div>
                    </div>
                    <div class="col-sm-7 f_l">
                        <p class="form-control-static" id="m_ccs"></p>
                    </div>
                </div>
                <div class="clearfix ins_select_list">
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-3">
                          <button type="button" id="back_btn" class="btn btn-primary btn-block">返回上一步</button>
                        </div>
                        <div class="col-sm-offset-2 col-sm-3">
                          <button type="submit" id="submit_btn" class="btn btn-primary btn-block" data-loading-text="数据递交中..." autocomplete="off">下一步</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    </block>
<block name="script">
<script type="text/javascript" src="__PUBLIC__/Green/js/insurance.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap-form-buttonset.min.js"></script>
<script type="text/javascript">
    var fee = {$calc_result},
        schemes = [{$scheme_qm},{$scheme_zl},{$scheme_jb}];
    
    function getM(cde){
        if(fee==null) return 0;
        for(var i=0;i<fee['KIND_LIST']['KIND'].length;i++){
            if(fee['KIND_LIST']['KIND'][i]['C_KIND_CDE']==cde)
                return parseFloat(fee['KIND_LIST']['KIND'][i]['N_PRM']);
        }
        return 0;
    }
    function calcScheme(n){
        if(n<0 || n>=3) return 0;
        var i,scheme = schemes[n],t=0;       
        for(i=0;i<scheme.length;i++){
            var cde = scheme[i][0],bjmp=scheme[i][1];
            t+=getM(cde);
            if(bjmp!=''){
                t+=getM(bjmp);
            }
        }
        t += parseFloat(fee['BASE']['N_TRAFF_REAL_PRM']) + parseFloat(fee['BASE']['N_TAX_REAL_PRM']);
        return t;
    }
    function setScheme(n){
        if(n<0 || n>=3) return;
        var i,scheme = schemes[n];
        $('#forms')[0].reset();
        $('.buttonset-rd').bsFormButtonset('attach');
        $('input.styled:enabled').prop('checked',false);
        $('input.bswitch').bootstrapSwitch('state',false);
        
        for(i=0;i<scheme.length;i++){
            var cde = scheme[i][0],bjmp=scheme[i][1];
            $('input[name="kinds[' + cde + '][flag]"]:checkbox').prop('checked',true);
            if(bjmp!=''){
                $('input[name="kinds[' + bjmp + '][flag]"]:checkbox').bootstrapSwitch('state',true);    
            }
        }
    }
    
    $('[data-toggle="popover"]').popover({container: 'body'});
    $('.buttonset-rd').bsFormButtonset('attach');
    $("input[name='stype']:radio").change(function(){
        var n = $(this).val();
        setScheme(parseInt(n));
    });
    
    function switch2cust(){
        $('#custom_label').trigger('click');
    }
    
    $("input[name!='stype']:radio").change(function(){
        switch2cust();
    });
    $('input.styled:enabled').change(function(){
        //关闭对应不计免赔
        var checked = $(this).prop('checked'),
            cde1 = $(this).attr('data');
        var i,scheme = schemes[0];
        
        for(i=0;i<scheme.length;i++){
            var cde = scheme[i][0],bjmp=scheme[i][1];
            if(cde == cde1 ){
                if(bjmp!=''){
                    $('input[name="kinds[' + bjmp + '][flag]"]:checkbox').bootstrapSwitch('state',checked);    
                }
                break;
            }
        }
        switch2cust();
    });
    
    $('#back_btn').click(function(){
        history.go(-1);
    });
    
    $(".bswitch").bootstrapSwitch();
    $().ready(function(){
        if(fee!=null){
            var i;
            for(i=0;i<3;i++){
                var t = calcScheme(i);
                $('#m_'+i).text('￥' +t.toFixed(2));
            }
            $('#m_jqx').text('￥'+fee['BASE']['N_TRAFF_REAL_PRM']);
            $('#m_ccs').text('￥'+fee['BASE']['N_TAX_REAL_PRM']);
        }
        setScheme(0);
    });
    $('#forms').validate({
        submitHandler:function(form){
                var self = $(form);
                $('#submit_btn').button('loading');
                $.post(self.attr('action'), self.serialize(), function(data){
                    if(data.status){
                        window.location.href = data.url;
                    } else {
                        $('#submit_btn').button('reset');
                        alert(data.info);
                    }
                }, "json");
            }            
    });
</script>
</block>
